package cn.net.zj.scan.ui;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.widget.Button;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;

import butterknife.BindView;
import butterknife.OnClick;
import cn.net.zj.scan.R;
import cn.net.zj.scan.utils.SharedPreferencesUtils;
import cn.net.zj.scan.utils.ZjConfig;

public class MainActivity extends BaseActivity {


    @BindView(R.id.tv_title)
    TextView tv_title;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }


    @Override
    public void init() {
        super.init();
        tv_title.setText("功能菜单");
    }

    @OnClick(R.id.bt_query)
    public void queryAction() {
        ActivityUtils.startActivity(OrderBrowserConditionActivity.class);
    }

    @OnClick(R.id.bt_out_house)
    public void onclick(Button view) {

        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, 1);
        } else {
            Intent intent = new Intent(MainActivity.this, outHouseActivity.class);
            startActivity(intent);
        }


    }

    @OnClick(R.id.bt_in_house)
    public void in_house(Button view) {

        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, 1);
        } else {
            Intent intent = new Intent(MainActivity.this, InHouseActivity.class);
            startActivity(intent);
        }


    }


    @OnClick(R.id.bt_logout)
    public void logout(Button view) {

        SharedPreferencesUtils.setParam(this, ZjConfig.userName, "");
        SharedPreferencesUtils.setParam(this, ZjConfig.userPassword, "");
        finish();

    }


//    private void submitInvoiceInfo(String invoicesListString) {
//        if (context != null) {
//            if (!NetWorkUtils.isNetworkConnected(context)) {
//                DialogUtils.showSetNetDialog(context);
//                return;
//            }
//        }
//        Log.e("出库中：",invoicesListString+"");
//        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),invoicesListString);
//        Observable<StateBean> observable = HttpMethods.getInstance().getFyApi().uploadData(body);
//        observable.subscribeOn(Schedulers.io())//切换到io线程请求网络
//                .observeOn(AndroidSchedulers.mainThread())//回到主线程处理请求结果
//                .subscribe(new Observer<StateBean>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//                        showProgressDialog("提示", "正在出库中，请稍后……");
//                    }
//                    @Override
//                    public void onNext(final StateBean resBean) {
//                        if (resBean.isFlag()){
//                            sView.showMsgToast("订单上传成功！", Toast.LENGTH_SHORT);
//                            labelDal.deleteInvoiceAll();
//                            productInfoDal.deleteProductInfo(account);
//                            start();
//                        }else {
//                            sView.showMsgToast(""+resBean.getMessage(), Toast.LENGTH_SHORT);
////                            labelDal.deleteInvoiceAll();
////                            productInfoDal.deleteProductInfo(account);
////                            start();
//                        }
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        sView.showMsgToast("连接异常："+e+"", Toast.LENGTH_SHORT);
//                        dismissProgress();
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        dismissProgress();
//                    }
//                });
//
//
//    }
//
//
//    private void updateCustomerInfo(String companyId) {
//        Observable<DistributorBean> observable = HttpMethods.getInstance().getFyApi().updateDistributor(companyId);
//
//        observable.subscribeOn(Schedulers.io())//切换到io线程请求网络
//                .observeOn(AndroidSchedulers.mainThread())//回到主线程处理请求结果
//                .subscribe(new Observer<DistributorBean>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//                        Log.d(TAG,"开始更新经销商列表");
//                    }
//
//                    @Override
//                    public void onNext(final DistributorBean resBean) {
//                        Log.e(TAG,"返回数据"+new Gson().toJson(resBean)+"");
//                        if (resBean.getData() != null && resBean.getData().size()>0) {
//                            insertConsigneeInfo(resBean.getData());
//                        }else {
//                            Toast.makeText(SettingActivity.this,"返回数据为空！", Toast.LENGTH_SHORT).show();
//                        }
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        dismissProgress();
//                        Log.e(TAG, "请求失败"+e.getMessage());
//                        Toast.makeText(SettingActivity.this,"请求失败！"+e.getMessage(), Toast.LENGTH_SHORT).show();
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        dismissProgress();
//                        Log.d(TAG, "请求成功");
//                    }
//                });
//    }
}
